# -*-coding = utf-8 -*-
# @Time : 2023/4/5 22:37
# @Author : Oliver
# @File : 数据清洗和特征选择.py
# @Software :PyCharm

import pandas as pd
from fuzzywuzzy import fuzz
from fuzzywuzzy import process

pd.set_option('display.width', 500)
pd.set_option('display.max_columns', 200)
data = pd.read_excel('.\\dataset\\sale.xls', sheet_name='Sheet1', header=0)

print('前5行:\n', data.head())
print('后5行:\n', data.tail())

# 每列的数据类型
print(data.dtypes)

# 每列的列名
print(data.columns)

# 新增total数据
data['total'] = data['Jan'] + data['Feb'] + data['Mar']
print('前5行:\n', data.head())

# 求和 最小值 最大值 平均值
print(data['Jan'].sum(), data['Jan'].min(), data['Jan'].max(), data['Jan'].mean())

s1 = data[['Jan', 'Feb', 'Mar', 'total']].sum()
print(s1)
s2 = pd.DataFrame(data=s1)
print(s2)
# 转置
print(s2.T)
s = s2.T.reindex(columns=data.columns, fill_value=0)
print(s)
# 将新增的s插入data
data = data.append(s, ignore_index=True)
print(data.tail())


def enum_row(row):
    print(row['name'])


# 枚举
data.apply(enum_row, axis=1)

# 模糊匹配
# 相似度比较
print(fuzz.ratio('python package', 'payhon package'))
